<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8'>
    <meta content='width=device-width, initial-scale=1.0' name='viewport'>
    <meta content='' name='description'>
    <meta content='Nils Nordman' name='author'>
    <link href='/images/howl.png' rel='shortcut icon'>
    <title>Howl :: Spec - howl.Completer</title>
    <link href="/stylesheets/bootstrap.min.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/syntax.css" media="screen" rel="stylesheet" type="text/css" />
    <link href="/stylesheets/howl.css" media="screen" rel="stylesheet" type="text/css" />
    <script src="https://code.jquery.com/jquery-1.12.3.min.js" type="text/javascript"></script>
    <script src="/javascripts/bootstrap.min.js" type="text/javascript"></script>
    
    <link href='//fonts.googleapis.com/css?family=Josefin+Slab' rel='stylesheet' type='text/css'>
    <link href='//fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
  </head>
  <body class='doc doc_spec doc_spec_completer_spec'>
    <div class='container'>
      <div class='masthead'>
        <ul class='nav nav-pills'>
          <li>
            <a href='/'>
              <span class='glyphicon glyphicon-home'></span>
              Home
            </a>
          </li>
          <li>
            <a href='/doc/'>
              <span class='glyphicon glyphicon-book'></span>
              Documentation
            </a>
          </li>
          <li>
            <a href='/blog/'>
              <span class='glyphicon glyphicon-bullhorn'></span>
              Blog
            </a>
          </li>
          <li>
            <a href='/contact.html'>
              <span class='glyphicon glyphicon-inbox'></span>
              Contact
            </a>
          </li>
        </ul>
      </div>
      <ol class="breadcrumb"><li><a href="/">Home</a></li><li><a href='../'>Howl 0.4 Documentation</a></li><li>Spec</li><li>Spec - howl.Completer</li></ol>
      <div class="spec-group spec-group-1">&#x000A;&#x000A;<h1 id="howl.completer">howl.Completer</h1>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">&#x000A;  </span><span class="n">buffer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Buffer</span><span class="w"> </span><span class="p">{}</span></pre>&#x000A;&#x000A;<h4 id=".start_pos-holds-the-start-position-for-completing">.start_pos holds the start position for completing</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'oh cruel word'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">9</span><span class="p">).</span><span class="n">start_pos</span></pre>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id=".complete">.complete<span class="arg-list">(pos [, limit])</span></h2>&#x000A;&#x000A;<h4 id="instantiates-completers-once-with-(buffer,-context)">instantiates completers once with (buffer, context)</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'mr.cat'</span><span class="w">&#x000A;</span><span class="n">factory</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="n">factory</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">factory</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="o">\</span><span class="n">context_at</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">factory</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="lookups-completers-in-completion-when-they-are-specified-as-strings">lookups completers in completion when they are specified as strings</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'yowser'</span><span class="w">&#x000A;</span><span class="n">factory</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">completion</span><span class="p">.</span><span class="n">register</span><span class="w"> </span><span class="ss">name:</span><span class="w"> </span><span class="s1">'comp-name'</span><span class="p">,</span><span class="w"> </span><span class="ss">:factory</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="s1">'comp-name'</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">factory</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called</span></pre>&#x000A;&#x000A;<h4 id="returns-completions-for-completers-in-buffer-and-mode">returns completions for completers in buffer and mode</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">completers:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'mode'</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w">  </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'buffer'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">completions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">completions</span><span class="p">,</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'buffer'</span><span class="p">,</span><span class="w"> </span><span class="s1">'mode'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-completions-for-mode-even-if-buffer-has-no-completers">returns completions for mode even if buffer has no completers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">completers:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'mode'</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'mode'</span><span class="w"> </span><span class="p">}</span></pre>&#x000A;&#x000A;<h4 id="returns-the-search-string-after-the-completions">returns the search string after the completions</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">completers:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'prefix'</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'pre'</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w">  </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'buffer'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="n">search</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">search</span><span class="p">,</span><span class="w"> </span><span class="s1">'pre'</span></pre>&#x000A;&#x000A;<h4 id="calls-&lt;completer.complete()&gt;-with-(completer,-context)">calls &lt;completer.complete()&gt; with (completer, context)</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'mr.cat'</span><span class="w">&#x000A;</span><span class="n">comp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">comp</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">6</span><span class="p">)</span><span class="w">&#x000A;&#x000A;</span><span class="n">completer</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">comp</span><span class="p">.</span><span class="n">complete</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">comp</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="o">\</span><span class="n">context_at</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;&#x000A;</span><span class="n">completer</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">7</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">comp</span><span class="p">.</span><span class="n">complete</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">comp</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="o">\</span><span class="n">context_at</span><span class="w"> </span><span class="mi">7</span></pre>&#x000A;&#x000A;<h4 id="returns-completions-from-just-one-completer-if-completions.authoritive-is-set">returns completions from just one completer if completions.authoritive is set</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="p">,</span><span class="w"> </span><span class="ss">authoritive:</span><span class="w"> </span><span class="kc">true</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'two'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">completions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'one'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">completions</span></pre>&#x000A;&#x000A;<h4 id="merges-duplicate-completions-from-different-completers">merges duplicate completions from different completers</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'yes'</span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'yes'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">completions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'yes'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">completions</span></pre>&#x000A;&#x000A;<h4 id="gives-a-final-boost-to-case-matching-completions,-all-else-equal">gives a final boost to case-matching completions, all else equal</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'he'</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'Hello'</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">completions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">3</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="s1">'Hello'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">completions</span><span class="w">&#x000A;&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'He'</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'hello'</span><span class="p">,</span><span class="w"> </span><span class="s1">'Hello'</span><span class="w"> </span><span class="p">}</span><span class="w">&#x000A;</span><span class="n">completions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">3</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s1">'Hello'</span><span class="p">,</span><span class="w"> </span><span class="s1">'hello'</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">completions</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(limiting completions)</span></h3>&#x000A;&#x000A;<h4 id="returns-at-most-`completion_max_shown`-completions">returns at most `completion_max_shown` completions</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">completions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="s2">"cand-</span><span class="si">#{</span><span class="n">i</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="mi">15</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">completions</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">completion_max_shown</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">3</span><span class="w">&#x000A;</span><span class="n">actual</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">1</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">3</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">actual</span></pre>&#x000A;&#x000A;<h4 id="returns-at-most-&lt;limit&gt;-completions-if-specified">returns at most &lt;limit&gt; completions if specified</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">completions</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="s2">"cand-</span><span class="si">#{</span><span class="n">i</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="mi">15</span><span class="p">]</span><span class="w">&#x000A;</span><span class="n">append</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">completers</span><span class="p">,</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="ss">complete:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="n">completions</span><span class="w">&#x000A;</span><span class="n">actual</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="o">\</span><span class="n">complete</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">4</span><span class="p">,</span><span class="w"> </span><span class="o">#</span><span class="n">actual</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;<div class="spec-group spec-group-2">&#x000A;&#x000A;<h2 id="accept">accept<span class="arg-list">(completion)</span></h2>&#x000A;&#x000A;<h4 id="returns-the-position-after-the-accepted-completion">returns the position after the accepted completion</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello there'</span><span class="w">&#x000A;  </span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">)</span><span class="o">\</span><span class="n">accept</span><span class="w"> </span><span class="s1">'hƏlp'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span></pre>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when hungry_completion is true)</span></h3>&#x000A;&#x000A;<h4 id="replaces-the-current-word-with-&lt;completion&gt;">replaces the current word with &lt;completion&gt;</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello there'</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">hungry_completion</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">true</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="o">\</span><span class="n">accept</span><span class="w"> </span><span class="s1">'hey'</span><span class="p">,</span><span class="w"> </span><span class="mi">3</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hey there'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(when hungry_completion is false)</span></h3>&#x000A;&#x000A;<h4 id="inserts-&lt;completion&gt;-at-the-start-position">inserts &lt;completion&gt; at the start position</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello there'</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">config</span><span class="p">.</span><span class="n">hungry_completion</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="p">)</span><span class="w">&#x000A;</span><span class="n">completer</span><span class="o">\</span><span class="n">accept</span><span class="w"> </span><span class="s1">'over'</span><span class="p">,</span><span class="w"> </span><span class="mi">7</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'hello overthere'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span></pre>&#x000A;</div>&#x000A;<div class="spec-group spec-group-3">&#x000A;&#x000A;<h3 id=""><span class="arg-list">(interacting with mode's .on_completion_accepted)</span></h3>&#x000A;&#x000A;<h4 id="invokes-it-with-(mode,-completion,-context)-if-present">invokes it with (mode, completion, context) if present</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">on_completion_accepted:</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">nil</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello there'</span><span class="w">&#x000A;</span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">)</span><span class="o">\</span><span class="n">accept</span><span class="w"> </span><span class="s1">'help'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">mode</span><span class="p">.</span><span class="n">on_completion_accepted</span><span class="p">).</span><span class="n">was_called_with</span><span class="w"> </span><span class="n">mode</span><span class="p">,</span><span class="w"> </span><span class="s1">'help'</span><span class="p">,</span><span class="w"> </span><span class="n">buffer</span><span class="o">\</span><span class="n">context_at</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span></pre>&#x000A;&#x000A;<h4 id="uses-it's-return-value-as-the-position-returned-if-it's-a-number">uses it's return value as the position returned if it's a number</h4>&#x000A;&#x000A;<pre class="highlight moonscript"><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">on_completion_accepted:</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="mi">6</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">mode</span><span class="w">&#x000A;</span><span class="n">buffer</span><span class="p">.</span><span class="n">text</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'hello there'</span><span class="w">&#x000A;</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="mi">6</span><span class="p">,</span><span class="w"> </span><span class="nc">Completer</span><span class="p">(</span><span class="n">buffer</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span><span class="p">)</span><span class="o">\</span><span class="n">accept</span><span class="w"> </span><span class="s1">'help'</span><span class="p">,</span><span class="w"> </span><span class="mi">4</span></pre>&#x000A;</div>&#x000A;</div>&#x000A;</div>
      <div class='footer text-muted'>
        <a href='/'>
          <img width="50" height="50" class="footer-logo" src="/images/howl.png" />
        </a>
        <div class='footer-follow'>
          <p>
            <a class='twitter-follow-button' data-lang='en' data-show-count='false' href='https://twitter.com/howleditor' rel='me'>
              Follow @howleditor
            </a>
          </p>
          <p>
            <a class='twitter-share-button' data-count='none' data-hashtags='howleditor' data-lang='en' data-text='The Howl Editor, a general purpose, light-weight customizable editor.' data-url='http://howl.io' href='https://twitter.com/share'>
              Tweet
            </a>
          </p>
        </div>
        <div class='footer-blurb'>
          <div>The Howl editor.</div>
          <div>
            Copyright 2012-2016
            <a class='alert-link' href='https://github.com/howl-editor/howl/contributors'>
              The Howl Developers.
            </a>
          </div>
        </div>
      </div>
    </div>
    <script>
      <!-- / GA -->
      (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
      })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
      ga('create', 'UA-45283282-1', 'howl.io');
      ga('send', 'pageview');
      <!-- / Twitter -->
      !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];
      if(!d.getElementById(id)){js=d.createElement(s);js.id=id;
      js.src="//platform.twitter.com/widgets.js";
      fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");
    </script>
  </body>
</html>
